package com.pussinboots.morning.cms.modules.system.order.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.pussinboots.morning.cms.modules.system.order.entity.OsOrder;
import com.pussinboots.morning.cms.modules.system.order.mapper.OsOrderMapper;
import com.pussinboots.morning.cms.modules.system.order.service.IOsOrderService;
import com.pussinboots.morning.cms.modules.system.product.entity.OsProduct;
import com.pussinboots.morning.common.model.PageInfo;

/**
 * <p>
 * 订单表 服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2017-04-12
 */
@Service
public class OsOrderServiceImpl extends ServiceImpl<OsOrderMapper, OsOrder> implements IOsOrderService {

	@Autowired
	private OsOrderMapper orderMapper;
	
	@Override
	public PageInfo selectByPullPage(PageInfo pageInfo) {
		//设置分页
		Page<OsProduct> page = new Page<>(pageInfo.getNowpage(), pageInfo.getSize());
		
		//设置排序
		String sortStr = pageInfo.getSort();
		
		//查询数据
		List<OsOrder> osOrderList = null;
		if(sortStr!=null && !sortStr.equals("")){
			osOrderList = orderMapper.selectPage(page, new EntityWrapper<OsOrder>().orderBy(sortStr, false));
		}else{
			osOrderList = orderMapper.selectPage(page, null);
		}
		
		//设置返回对象
        pageInfo.setTotal(page.getTotal());
        pageInfo.setRows(osOrderList);
        
        //返回数据
		return pageInfo;
	}

	@Override
	public Integer selectAllOrderNumber(Integer status) {
		Integer count = 0;
		if(status!=null){
			EntityWrapper<OsOrder> wrapper = new EntityWrapper<OsOrder>();
			wrapper.where("status={0}",status); 
			count = orderMapper.selectCount(wrapper);
		}else{
			count = orderMapper.selectCount(null);
		}
		return count;
	}
	
}
